package com.zbkj.crmeb.agent.controller;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.crmeb.core.common.CommonResult;
import com.crmeb.core.exception.CrmebException;
import com.utils.CrmebUtil;
import com.zbkj.crmeb.agent.request.AgentAccountCenterRequest;
import com.zbkj.crmeb.agent.service.AgentAccountService;
import com.zbkj.crmeb.chant.response.AccountCenterResponse;
import com.zbkj.crmeb.finance.controller.WithdrawalAuditRequest;
import com.zbkj.crmeb.finance.response.UserRechargeResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;


/**
 * <p>
 * 服务商资金账户表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-02-15
 */
@RestController
@RequestMapping("/api/admin/agent-account")
@Api(tags = "总后台-服务商账户")
public class AgentAccountController {

    @Autowired
    AgentAccountService agentAccountService;

    @ApiOperation(value = "服务商账户中心")
    @GetMapping(value = "/account/center")
    public CommonResult<AccountCenterResponse> agentAccountCenter(@Validated AgentAccountCenterRequest request){
        if(null == request.getAgentId()){
            throw new CrmebException("服务商id不能为空!");
        }
        return CommonResult.success(agentAccountService.agentAccountCenter(request));
    }

    @ApiOperation(value = "冻结/解冻服务商账户")
    @GetMapping(value = "/account/frozen/{id}/{status}")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id", value="服务商id"),
            @ApiImplicitParam(name="status", value="状态 0解冻 1冻结")
    })
    public CommonResult<String> accountFrozen(@PathVariable("id") Integer id, @PathVariable("status") Integer status){
        return agentAccountService.accountFrozen(id,status) ? CommonResult.success() : CommonResult.failed();
    }

    @ApiOperation(value = "服务商提现详情")
    @GetMapping(value = "/info/{id}")
    public CommonResult<UserRechargeResponse>  getList(@PathVariable Integer id){
        return CommonResult.success(agentAccountService.getRechargeInfo(id));
    }

    @ApiOperation(value = "服务商提现审核")
    @PutMapping("/withdrawal/audit")
    public CommonResult<Object> withdrawalAudit(@RequestBody @Validated WithdrawalAuditRequest req, HttpServletRequest request){
        return agentAccountService.offlineWithdrawAudit(req, CrmebUtil.getClientIp(request));
    }

    @ApiOperation(value = "服务商账户中心查看详情")
    @GetMapping(value = "/account/info/{id}")
    public CommonResult<Object> accountInfo(@PathVariable("id") Integer id){
        return CommonResult.success(agentAccountService.accountInfo(id));
    }


}

